package com.ayoka.parenting.mvp;

import java.lang.ref.WeakReference;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: BasePresenterImpl.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class BasePresenterImpl<V extends BaseView> implements BasePresenter<V>{

    protected static String TAG;

    protected WeakReference<V> mView;

    @Override
    public void attachView(V view) {
        TAG = getClass().getSimpleName();
        mView = new WeakReference<>(view);
    }

    @Override
    public void detachView() {
        if (isAttached()) {
            mView.clear();
            mView = null;
        }
    }

    @Override
    public boolean isAttached() {
        return mView != null && mView.get() != null;
    }
}
